package tech.yunland.shop.domain.model;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * @author 文卡<wkwenka@gmail.com>  on 17-2-22.
 */
@Entity
@Table(name = "finance_bill")
public class FinanceBill extends Bill {

    @ManyToOne
    private Goods goods;

    @Column(nullable = false)
    private Integer direction; //方向 -1:支出 1:收入

    private BigDecimal payment = BigDecimal.ZERO; //应该收付款

    @Column(name = "actual_payment")
    private BigDecimal actualPayment = BigDecimal.ZERO; //实际收付款

    private BigDecimal quantity = BigDecimal.ZERO; //数量

    private BigDecimal amount = BigDecimal.ZERO; //总价

    @Transient
    private String goodsName;

    @Transient
    private String goodsPrice;


    public Goods getGoods() {
        return goods;
    }

    public void setGoods(Goods goods) {
        this.goods = goods;
    }

    public Integer getDirection() {
        return direction;
    }

    public void setDirection(Integer direction) {
        this.direction = direction;
    }

    public BigDecimal getPayment() {
        return payment;
    }

    public void setPayment(BigDecimal payment) {
        this.payment = payment;
    }

    public BigDecimal getActualPayment() {
        return actualPayment;
    }

    public void setActualPayment(BigDecimal actualPayment) {
        this.actualPayment = actualPayment;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public BigDecimal getAmount() {
        return quantity.multiply(actualPayment);
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public String getGoodsName() {
        return goods != null ? goods.getName() : this.goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsPrice() {
        return goods != null ? goods.getName() : this.goodsPrice;
    }

    public void setGoodsPrice(String goodsPrice) {
        this.goodsPrice = goodsPrice;
    }
}
